package com.businessportal.web.common;

import javax.servlet.http.HttpServletRequest;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Vadim on 6/27/14.
 */
public class WebServletHelper {
    public static String getUrlBase(HttpServletRequest request)
            throws MalformedURLException {
        URL requestUrl = new URL(request.getRequestURL().toString());
        String portString =
                requestUrl.getPort() == -1 ? "" : ":" + requestUrl.getPort();
        return requestUrl.getProtocol() +
                "://" + requestUrl.getHost() + portString + "/";
    }

}
